import request from '@/utils/request';
import { PageResponse } from '@/interface/pages';

/**
 * 获取分页列表
 *
 * @returns Promise
 *
 * @todo 发起axios请求
 */
export const getUsersList = (params: API.user.PageListDto) => {
  return request<PageResponse<API.user.EntitySchema[]>>({
    url: '/admin/user',
    method: 'get',
    params
  });
};

/**
 * 获取下级团队
 *
 * @returns Promise
 *
 * @todo 发起axios请求
 */
export const getUserTeam = (ownId: string) => {
  return request<API.user.EntitySchema[]>({
    url: `/admin/user/team/${ownId}`,
    method: 'get'
  });
};

/**
 * 获取详情
 *
 * @returns Promise
 *
 * @todo 发起axios请求
 */
export const getUsersDetail = (ownId: string) => {
  return request<API.user.EntitySchema>({
    url: `/admin/user/${ownId}`,
    method: 'get'
  });
};

/**
 * 编辑
 *
 * @param ownId
 * @param data
 * @returns Promise
 *
 * @todo 发起axios请求
 */
export const updateUsers = (ownId: string, data: API.user.EntityDto) => {
  return request({
    url: `/admin/user/${ownId}`,
    method: 'put',
    data
  });
};

/**
 * 申请邀请码
 *
 * @param ownId
 * @returns Promise
 *
 * @todo 发起axios请求
 */
export const createUniqueCode = (ownId: string): Promise<any> => {
  return request<string>({
    url: `/admin/user/unique/${ownId}`,
    method: 'put'
  });
};

/**
 * 修改状态
 *
 * @param id
 * @param state
 * @returns Promise
 *
 * @todo 发起axios请求
 */
export const updateSwitch = (ownId: string, data: { state?: boolean }) => {
  return request({
    url: `/admin/user/switch/${ownId}`,
    method: 'put',
    data
  });
};
